//
//  CollectionViewCell.m
//  CollectionViewSubscriptionLabel
//
//  Created by chenyk on 15/4/24.
//  Copyright (c) 2015年 chenyk. All rights reserved.
//

#import "CollectionViewCell.h"
#import "UIColor+Extension_YF.h"


@implementation CollectionViewCell
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (id)initWithCoder: (NSCoder *)aDecoder {
    self = [super initWithCoder: aDecoder];
    if (self) {
        self = [self sharedInit];
    }
    return self;
}
- (id)sharedInit {
    [self setup];
    return self;
}

- (void)setup {
    self.titleLabel = [UILabel new];
    self.titleLabel.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:12];
    
    self.titleLabel.layer.cornerRadius = 3.0;
    self.titleLabel.layer.masksToBounds = YES;
    self.state = CellStateNormal;
    
    [self.contentView addSubview:self.titleLabel];
}
- (void)setModel:(YFGoodsTypeSubModel *)model{
    _model = model;
    
    self.titleLabel.text = model.item;
    
    NSLog(@"state = %@", model.state);

    if (model.state.intValue == 0) {
        self.state = CellStateUnEnable;
        
    }else if (model.state.intValue == 1) {
        self.state = CellStateNormal;
        
    }else if (model.state.intValue == 2) {
        self.state = CellStateSelected;
    }
}

- (void)setState:(CellState)state {
    _state = state;

    if (state == CellStateNormal) { // 一般状态
        self.titleLabel.backgroundColor = YFColor_Background;
        self.titleLabel.textColor = YFColor_Text;
        
    }else if (state == CellStateSelected) { // 选中状态
        self.titleLabel.backgroundColor = YFColor_Red;
        self.titleLabel.textColor = [UIColor whiteColor];
        
    }else if (state == CellStateUnEnable) {  // 不可点击
        self.titleLabel.backgroundColor = YFColor_Background;
        self.titleLabel.textColor = [UIColor colorWithHexString:@"999999"];
    }
}

@end
